$(function() {
	show();

})


function show() {
	var customer = $("#customer").val(); //客户名称
	var goodsBillCode = $("#goodsBillCode").val(); //货运单编号
	var appealDate = $("#appealDate").val(); //投诉日期
	var ifHandle = $("#ifHandle").val(); //是否处理
	$.ajax({
		url: 'http://localhost:9000/customer/complaintinformation/show?customer=' + customer + '&goodsBillCode=' +
			goodsBillCode + '&appealDate=' + appealDate + '&ifHandle=' + ifHandle,
		type: 'get',
		dataType: 'json',
		success: function(complaintInformations) {
			var content = '';
			for (var i = 0; i < complaintInformations.length; i++) {
				var po = complaintInformations[i];
				// alert(po);
				if ((i + 1) % 2 == 0) {
					content += '<tr class="success">';
				} else {
					content += '<tr>';
				}
				content +=
					'<td style="width:80px;vertical-align:middle">' + po.customer + '</td>' +
					'<td style="width:150px;vertical-align:middle">' + po.goodsBillCode + '</td>' +
					'<td style="vertical-align:middle">' + po.appealContent + '</td>' +
					'<td style="width:100px;vertical-align:middle">' + po.appealDate + '</td>' +
					'<td style="width:80px;vertical-align:middle">' + po.ifHandle + '</td>' +
					'<td style="width:80px;vertical-align:middle">' + po.dealDate + '</td>' +
					'<td style="width:80px;vertical-align:middle">' + po.dealResult + '</td>' +
					'<td style="width:80px;vertical-align:middle">' + po.ifCallback + '</td>' +
					'<td style="width:80px;vertical-align:middle">' + po.callBackDate + '</td>' +
					'<td style="width:80px;vertical-align:middle">' + po.dealPerson + '</td>';
				if (po.ifHandle == "未处理") {
					content += '<td style="width:80px;vertical-align:middle">'+
						'<div style="float:left;width: 100px">' +
						'	<button type="button" class="btn btn-primary form-control" data-toggle="modal" data-target="#myModal">' +
						'		处理' +
						'	</button>' +
						'	<div class="modal fade" id="myModal">' +
						'		<div class="modal-dialog modal-sm">' +
						'			<div class="modal-content">' +
						'				<div class="modal-header">' +
						'					<h4 class="modal-title" style="text-align:center">投诉管理</h4>' +
						'					<button type="button" class="close" data-dismiss="modal">&times;</button>' +
						'				</div>' +
						'				<div class="modal-body" id="details">' +
						'					<table class="table table-bordered" style="margin-top: 20px;text-align: center">' +
						'						<thead style="text-align: center">' +
						'							<tr class="success" style="text-align: center">' +
						'								<th>方式</th>' +
						'							</tr>' +
						'						</thead>' +
						'						<tbody id="content">' +
						'							<tr>' +
						'								<th><button class="btn form-control btn-primary" onclick="refund(' + po.ciid + ')" >退款</button></th>' +
						'							</tr>' +
						'							<tr>' +
						'								<th><button class="btn form-control btn-primary" onclick="ignore(' + po.ciid + ')" >忽视</button></th>' +
						'							</tr>' +
						'							<tr>' +
						'								<th><button class="btn form-control btn-primary" onclick="handle3(' + po.ciid +
						')" >惩罚</button></th>' +
						'							</tr>' +
						'							<tr>' +
						'								<th><button class="btn form-control btn-primary" onclick="handle4(' + po.ciid +
						')" >啥啥</button></th>' +
						'							</tr>' +
						'						</tbody>' +
						'					</table>' +
						'				</div>' +
						'				<div class="modal-footer">' +
						'					<button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>' +
						'				</div>' +
						'			</div>' +
						'		</div>' +
						'	</div>' +
						'</div>'

						+
						'</td>';
				} else {
					content += '<td style="width:80px;vertical-align:middle">已处理</td>';
				}
				content += '</tr>';
			}
			$("#content").html(content);
		}
	})
}

/**
 * @param {Object} ciid
 * 投诉处理方式1:退款
 */
function refund(ciid) {
	//服务器端从session中获取当前操作者/管理员姓名

	$.ajax({
		url: 'http://localhost:9000/customer/complaintinformation/refund?ciid=' + ciid,
		type: 'get',
		dataType: 'json',
		success: function(map) {
			var msg = map.msg;
			if (msg.indexOf("成功") != -1) {
				alert(msg);
				window.location.href = 'complaintInformation.html';
			} else {
				alert(msg + ",请重试");
			}
		}
	})
}

/**
 * @param {Object} ciid
 * 投诉处理方式2：忽视
 */
function ignore(ciid) {
	//服务器端从session中获取当前操作者/管理员姓名

	$.ajax({
		url: 'http://localhost:9000/customer/complaintinformation/ignore?ciid=' + ciid,
		type: 'get',
		dataType: 'json',
		success: function(map) {
			var msg = map.msg;
			if (msg.indexOf("成功") != -1) {
				alert(msg);
				window.location.href = 'complaintInformation.html';
			} else {
				alert(msg + ",请重试");
			}
		}
	})
}
